import argostranslate.package
import argostranslate.translate

from_code = 'en'
to_code = 'zh'

argostranslate.package.update_package_index()  # 更新索引
available_packages = argostranslate.package.get_available_packages()  # 可翻译的语言
package_to_install = next(filter(lambda x: x.from_code == from_code and x.to_code == to_code, available_packages))
path = package_to_install.download()  # 下载包
argostranslate.package.install_from_path(path)  # 安装

translated_text = argostranslate.translate.translate('friends', from_code, to_code)
print(translated_text)
# 朋友
